# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  include AuthlogicMethods
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  filter_parameter_logging :password, :password_confirmation
  helper_method :current_user_session, :current_user

  private
  
  def current_user_session
    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
  end

  def current_user
    return @current_user if defined?(@current_user)
    @current_user = current_user_session && current_user_session.record
  end


  def require_user
    #unless current_user
    #store_location
    #flash[:notice] = "You must be logged in to access this page"
    #redirect_to login_path
    #return false

    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
    #end
  end

  def require_no_user
    #if current_user
    #store_location
    #flash[:notice] = "You must be logged out to access this page"
    #redirect_to root_url
    #return false
    return @current_user if defined?(@current_user)
    @current_user = current_user_session && current_user_session.user
    #end
  end

  def count_tags
    @tags = Document.tag_counts_on(:tags)
  end




  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
end
